/*
 * $Id: ActOnWatchSysHandshakeInfoDAO.java,v 1.2 2009/07/10 14:41:10 navdeep_mahajan Exp $
 * 
 * Copyright (C) 2006 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.common.database.dao;

import java.util.Date;

import com.ge.healthcare.autosc.common.ASCUtil;
import com.ge.healthcare.autosc.common.database.pojo.ActOnwatchSysHandShakeInfo;

/**
 * @author 212042764
 * 
 */
public class ActOnWatchSysHandshakeInfoDAO extends BaseDAO implements
		IOnWatchSysHandShakeInfoDAO {

	/**
	 * Eclipse generated
	 */
	private static final long serialVersionUID = 1566340732865698392L;
	private static final String TABLE_NAME = "com.ge.healthcare.autosc.common.database.pojo.ActOnwatchSysHandShakeInfo";
	private static final String COL_SYSTEM_ID = "systemId";

	public ActOnWatchSysHandshakeInfoDAO() {
		super(TABLE_NAME);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ge.healthcare.autosc.common.database.dao.IOnWatchSysContactInfoDAO
	 * #getSysContactInfoBySystemId(java.lang.String)
	 */
	public ActOnwatchSysHandShakeInfo getSysContactInfoBySystemId(
			String systemId) {
		return (ActOnwatchSysHandShakeInfo) findObjectByID(COL_SYSTEM_ID,
				systemId);
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.IOnWatchSysHandShakeInfoDAO#saveContactInfo(java.lang.String,
	 *      java.util.Date, java.util.Date)
	 */
	public void saveContactInfo(String systemId, Date lastContactDt,
			Date nextContactDt) {
		ActOnwatchSysHandShakeInfo contactInfo = this
				.getSysContactInfoBySystemId(systemId);

		if (ASCUtil.isNullOrEmptyObject(contactInfo)) {
			contactInfo = new ActOnwatchSysHandShakeInfo();
			contactInfo.setSystemId(systemId);
		}
		contactInfo.setLastContactTime(lastContactDt);
		contactInfo.setNextContactTime(nextContactDt);
		this.save(contactInfo);
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.IOnWatchSysHandShakeInfoDAO#saveContactInfo(java.lang.String,
	 *      java.util.Date, java.lang.Long)
	 */
	public void saveContactInfo(String systemId, Date lastContactDt,
			Long nextPollDurationInSec) {
		if (!ASCUtil.isNullOrEmpty(systemId)) {
			if (ASCUtil.isNullOrEmptyObject(nextPollDurationInSec)) {
				this.saveContactInfo(systemId, lastContactDt, (Date) null);
			} else {
				this
						.saveContactInfo(systemId, lastContactDt, new Date(
								lastContactDt.getTime() + nextPollDurationInSec
										* 1000));
			}
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ge.healthcare.autosc.common.database.dao.IOnWatchSysContactInfoDAO
	 * #saveAlways(java.lang.Object)
	 */
	public void saveAlways(Object pojo) {
		super.save(pojo);
	}

}
